package com.buaa.homework3;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private Button bu;
    private int flag ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bu = (Button)findViewById(R.id.bu);
        bu.setOnClickListener(this);
    }

    public void play(View view) {

        Intent intent = new Intent("music");
        intent.putExtra("action",flag);
        startService(intent);
    }

    @Override
    public void onClick(View v) {
        if("play".equals(bu.getText().toString())) {
            flag = 1;
            bu.setText("pause");
        }
        if("pause".equals(bu.getText().toString())) {
            flag = 2;
            bu.setText("play");
        }
    }
}
